home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / TANK11.ZIP / SOURCE.ZIP / HIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-16  |  1.1 KB  |  36 lines

  1. /* HIT contains the collision detection routines */
  2.  
  3. #include <conio.h>
  4. #include "tankdefs.h"
  5. #include "types.h"
  6. #include "extern.h"
  7.  
  8. int hit( int x, int y, int xdim, int ydim, int dir)
  9. /*    requires:    x,y coords of upper left corner object
  10.  *                 xdim,ydim object dimensions
  11.  *                 dir = direction to check
  12.  * ensures:     global vars HitX,HitY are the coordinates
  13.  *             of the pixel that caused the hit
  14.  * returns:       color of first non-zero element in approp direction
  15.  * notes:        assumes background color is 0, video mode 13         */
  16. {
  17.  long    int ofs,i;
  18.  
  19.     if (dir&2) {
  20.         if (dir==UP) ofs=(HitY=(y-1))*320+x;     /* UP    */
  21.         else         ofs=(HitY=(y+ydim))*320+x;  /* DOWN  */
  22.         for (i=ofs;i<ofs+xdim;i++) {
  23.             if (*(vbuf + i)) { HitX=i-ofs+x; return (int) *(vbuf + i);}
  24.         }
  25.         return 0; /* no collision */
  26.     }
  27.     else {
  28.         if (dir==LEFT) ofs=y*320+(HitX=x-1);        /* LEFT */
  29.        else ofs=y*320+(HitX=x+xdim);                    /* RIGHT */
  30.         for (i=0;i<ydim;i++) {
  31.             if (*(vbuf +ofs)) { HitY=i+y; return (int) *(vbuf+ofs); }
  32.             ofs+=320;
  33.         }
  34.         return 0; /* no collision */
  35.     }
  36. }